package com.ruoyi.web.controller.crm;

import com.bonuo.crm.domain.Payment;
import com.bonuo.crm.service.PaymentService;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.math.BigDecimal;
import java.util.List;

/**
 * 项目回款Controller
 * 
 * @author ruoyi
 * @date 2025-07-02
 */
@Api(tags = "项目回款管理")
@RestController
@RequestMapping("/crm/payment")
public class PaymentController extends BaseController
{
    @Autowired
    private PaymentService paymentService;

    /**
     * 查询项目回款列表
     */
    @GetMapping("/list")
    @ApiOperation(value = "查询项目回款列表",httpMethod = "GET")
    public TableDataInfo list(Payment Payment,Integer pageNum,Integer pageSize)
    {
        if(pageNum!=null && pageSize!=null){
            startPage();
        }
        List<Payment> list = paymentService.selectProjectPaymentList(Payment);
        //查询总百分比
        BigDecimal bigDecimal = paymentService.selectRatioByProjectId(Payment.getProjectId());
        return getDataTable(list,bigDecimal);
    }


    /**
     * 新增项目回款
     */
    @ApiOperation(value = "新增项目回款",httpMethod = "POST")
    @PostMapping("/add")
    public AjaxResult add(@RequestBody Payment payment)
    {
        return toAjax(paymentService.insertProjectPayment(payment));
    }

    /**
     * 修改项目回款
     */
    @ApiOperation(value = "修改项目回款",httpMethod = "PUT")
    @PutMapping("/update")
    public AjaxResult update(@RequestBody Payment payment)
    {
        return toAjax(paymentService.updateProjectPayment(payment));
    }

    /**
     * 删除项目回款
     */
    @ApiOperation(value = "删除项目回款",httpMethod = "DELETE")
	@DeleteMapping("/delete/{id}")
    public AjaxResult delete(@PathVariable Integer id)
    {
        return toAjax(paymentService.deleteProjectPaymentById(id));
    }
}